package com.sun.framework.controller;

import com.sun.common.pojo.Result;
import com.sun.common.pojo.SsqQuery;
import com.sun.common.pojo.SsqVo;
import com.sun.framework.service.SsqDataService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.sun.common.pojo.Result.success;

@Slf4j
@RestController
@RequestMapping("/ssq")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SsqController {

    private final SsqDataService ssqDataService;

    // http://localhost:8888/ssq/findWinningDataByCondition
    // 根据条件查询中奖数据
    @PostMapping("findWinningDataByCondition")
    public Result<List<SsqVo>> findWinningDataByCondition(@RequestBody SsqQuery ssqQuery) {
        long startTime = System.currentTimeMillis();
        List<SsqVo> result = ssqDataService.findWinningDataByCondition(ssqQuery);
        log.info("count：{} time：{}", result.size(), (System.currentTimeMillis() - startTime));
        return new Result<>(result);
    }

    // http://localhost:8888/ssq/updateLatestWinningData
    // 更新最新中奖数据
    @GetMapping("/updateLatestWinningData")
    public Result<Boolean> updateLatestWinningData() {
        ssqDataService.updateLatestWinningData();
        return success();
    }

}
